package com.baixun.gasadmin.controller;

import com.baixun.gasentity.entity.UserUrl;
import com.baixun.gassystem.service.DataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: 上海燃气驾驶舱
 * @description:
 * @author: yesong
 **/
@RestController
@RequestMapping("/json-data")
@Api(tags = "前端数据上传接口", description = "提供 JSON 数据的上传和修改接口")
public class DataController {

    @Autowired
    private DataService dataService;

    @PostMapping("/upload")
    @ApiOperation("上传 JSON 数据")
    public String uploadData(@RequestParam String frontEndData, @RequestBody String jsonData) {
        boolean success = dataService.uploadData(frontEndData, jsonData);
        return success ? "上传成功" : "上传失败";
    }

    @PutMapping("/update/{id}")
    @ApiOperation("修改指定 ID 的 JSON 数据")
    public String updateData(@PathVariable Long id, @RequestParam String frontEndData, @RequestBody String jsonData) {
        boolean success = dataService.updateData(id, frontEndData, jsonData);
        return success ? "更新成功" : "未找到指定 ID 的数据";
    }

    //记录用户登录信息
    @PostMapping("/userUrl")
    @ApiOperation("")
    public String userUrl(@RequestBody UserUrl url) {
        return dataService.getData(url);
    }
}
